/**
 * 
 */
package org.ejc.statistics.charts;

import java.io.Serializable;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;

import org.jfree.data.category.DefaultCategoryDataset;

import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;

/**
 * @author Brian Boyle
 *
 */
public class BarChart implements DatasetProducer, Serializable {

	public String[] categories;
	private int[] values;
	public String[] seriesNames;
	
	/**
	 * 
	 */
	public BarChart(Map map) {
		categories = new String[map.size()];
		seriesNames = new String[map.size()];
		values = new int[map.size()];
		Iterator iter = map.keySet().iterator();
		int count = 0;
		while(iter.hasNext()){
			String key = iter.next().toString();
			seriesNames[count] = key;
			Integer currentValue = (Integer) map.get(key);
			values[count] = currentValue.intValue();
			categories[count] = "";
			count++;
		}
	}

	/* (non-Javadoc)
	 * @see de.laures.cewolf.DatasetProducer#produceDataset(java.util.Map)
	 */
	public Object produceDataset(Map arg0) throws DatasetProduceException {
		DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
		for (int i = 0; i < categories.length; i++) {
			int currentValue = values[i];
			barDataset.addValue(currentValue, seriesNames[i], categories[i]);
		}
		
		return barDataset;
	}

	/* (non-Javadoc)
	 * @see de.laures.cewolf.DatasetProducer#hasExpired(java.util.Map, java.util.Date)
	 */
	public boolean hasExpired(Map arg0, Date arg1) {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see de.laures.cewolf.DatasetProducer#getProducerId()
	 */
	public String getProducerId() {
		// TODO Auto-generated method stub
		return null;
	}

}
